package demo.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import demo.service.PriceService;

import java.io.IOException;
import java.util.Map;

/**
 * @author JiangHaoTing
 * @create: 2021-09-27 17:21
 */
@Controller
@RequestMapping("/auth")
public class WebController {

    @GetMapping("index")
    @ResponseBody
    public ResponseEntity<String> index(){
        return ResponseEntity.ok("请求成功");
    }

    @Autowired
    private PriceService excelService;

    @PostMapping("/upload1")
    @ResponseBody
    public void uploadExcel() throws IOException {
        // 调用服务层解析 Excel 文件
//        excelService.parseExcel(file);
        return ;
    }

    /**
     * 成本计算
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("/upload")
    @ResponseBody
    public Map<String,String> uploadExcel2(@RequestParam("file") MultipartFile file) throws IOException {
        // 调用服务层解析 Excel 文件
        return excelService.parseExcel2(file);
    }


    @PostMapping("/upload22")
    @ResponseBody
    public Map<String,String> uploadExcel2(@RequestParam("shouzhimingxiFile") MultipartFile shouzhimingxiFile, @RequestParam("fangkuanFile") MultipartFile fangkuanFile) throws IOException {
        // 调用服务层解析 Excel 文件
        return excelService.parseExcel22(shouzhimingxiFile, fangkuanFile);
    }



    @PostMapping("/upload3")
    @ResponseBody
    public Map<String,String> upload3(@RequestParam("dingdangailan") MultipartFile dingdangailan,
                                      @RequestParam("shouruzhichu") MultipartFile shouruzhichu) throws IOException {

        // 调用服务层解析 Excel 文件
        return excelService.parseExcel3(dingdangailan, shouruzhichu);
    }




}
